package parser;

import antlr.RecognitionException;
import antlr.Token;
import java.util.*;

class Dictionary extends Expr {
    
    List<Expr> args;
    
    Dictionary(List<Expr> args) {
        this.args = args;
    }

    void write(ByteStream out) throws RecognitionException {
        int size = args.size();
        out.write(Opcodes.DICTIONARY);
        for(int i = 0; i < size; i += 2) {
            args.get(i+1).write(out);  // d v
            out.write(Opcodes.OVER); // d v d 
            args.get(i).write(out);  // d v d k
            out.write(Opcodes.SETITEM); // d ( d[k] = v )
        }
    }
    
    void writeLHS(ByteStream out) throws RecognitionException {
        throw new Error("Not implemented");
    }

    void delete(ByteStream out) throws RecognitionException {
        throw new RecognitionException("Cannot delete rvalue");
    }
  
}
